---
title: Server
description: Server-side API and runtime for Expo Router projects.
sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-server'
packageName: 'expo-server'
platforms: ['server']
isNew: true
---

import { BookOpen02Icon } from '@expo/styleguide-icons/outline/BookOpen02Icon';

import APISection from '~/components/plugins/APISection';
import { APIInstallSection } from '~/components/plugins/InstallSection';
import { BoxLink } from '~/ui/components/BoxLink';

`expo-server` is a server-side API and runtime library for Expo Router. It provides helpers you can use in your Expo Router API routes or other server code, and contains adapters to run Expo Router server exports.

## Installation

<APIInstallSection packageName="expo-server" hideBareInstructions />

To use `expo-server` in your project, you need to configure your Expo Router project to export in `server` mode. Follow the instructions from Expo Router's API Routes guide:

<BoxLink
  title="API Routes"
  description="Learn how to create server endpoints with Expo Router."
  href="/router/web/api-routes"
  Icon={BookOpen02Icon}
/>

## Usage

`expo-server`'s runtime APIs can only be used in server-side code and give you access to the server-side runtime environment. The runtime API exposes functions that can be called within the async context of request handlers and give you information about the current request or schedule tasks that run concurrently to the incoming request.

### Accessing request metadata

```ts
import { origin, environment } from 'expo-server';

export async function GET() {
  return Response.json({
    isProduction: environment() == null,
    isStaging: environment() === 'staging',
    origin: origin(),
  });
}
```

### Scheduling tasks

```ts
import { runTask, deferTask } from 'expo-server';

export async function GET() {
  runTask(async () => {
    console.log('will run immediately.');
  });

  deferTask(async () => {
    console.log('will run after the response resolved.');
  });

  return Response.json({ success: true });
}
```

## Adapters

`expo-server` exposes adapters to run Expo Router server-side exports in different environments or on different cloud provider serverless functions. Typically, every runtime needs its own adapter to function with the `expo-server` runtime. Before deploying to these providers, it is good to be familiar with the basics of [`npx expo export`](/more/expo-cli#exporting) command.

| Adapter                       | Provider                                                                 |
| ----------------------------- | ------------------------------------------------------------------------ |
| `expo-server/adapter/bun`     | [Bun](https://bun.com/docs)                                              |
| `expo-server/adapter/express` | [Express](https://expressjs.com/en/5x/api.html)                          |
| `expo-server/adapter/http`    | [Node.js](https://nodejs.org/api/http.html)                              |
| `expo-server/adapter/netlify` | [Netlify Functions](https://docs.netlify.com/build/functions/overview/)  |
| `expo-server/adapter/vercel`  | [Vercel Functions](https://vercel.com/docs/functions)                    |
| `expo-server/adapter/workerd` | [Cloudflare Workers](https://developers.cloudflare.com/pages/functions/) |

To learn how to host API routes on different third-party services, follow the instructions from Expo Router's API Routes guide:

<BoxLink
  title="API Routes"
  description="Learn how to host API Routes on third-party services."
  href="/router/web/api-routes#hosting-on-third-party-services"
  Icon={BookOpen02Icon}
/>

By convention, all adapters export a `createRequestHandler` function that accepts a parameters object. This accepts a `build` parameter that must be set to the relative path to the `dist/server` output directory that `npx expo export` created. Some adapters may also accept more values to configure the runtime API.

```ts
import path from 'node:path';
import { createRequestHandler } from 'expo-server/adapter/http';

const onRequest = createRequestHandler({
  build: path.join(process.cwd(), 'dist/server'),
  environment: process.env.NODE_ENV,
});
```

## API

<APISection packageName="expo-server" />
